module CategoriesHelper
  def categories_options(categories = Category.find(:all,:conditions =>['parent_id is null']))
    options =Array.new
    for category in categories
      create_category_options(category,options)
    end
    return options
  end

  def create_category_options(category,options)
    optioin_item =Array.new
    optioin_item[1]= category.id.to_s
    optioin_item[0]= category.title
    options << optioin_item
    if category.children.length > 0
      category.children.each do |c|
        create_category_options(c,options)
      end
    end
  end
end
